package com.ysd.qxgl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import com.ysd.qxgl.dto.IRolesDTO;
import com.ysd.qxgl.model.Roles;
import com.ysd.qxgl.service.IRolesService;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(path = "/roles",method = RequestMethod.POST)
public class RolesController {
@Resource
private IRolesService rolesService;
@ApiOperation(value = "查询所有角色")
@GetMapping("/findAll")
@ResponseBody
public Map findAll(IRolesDTO dto){
    List<Roles> list=rolesService.findAll(dto);
    Map<String,Object> map=new HashMap<String,Object>();
    map.put("code", 0);
    map.put("msg", "查询成功");
    map.put("count", rolesService.getCount(dto));
    map.put("data", list);
    return map;
}
@ApiOperation(value = "添加或修改角色",notes = "添加或修改")
@PostMapping("/addOrEdit")
public void addOrEdit(@RequestBody Roles role){
    rolesService.addOrEdit(role);
}
 @ApiOperation(value = "删除")
 @DeleteMapping("/del/{id}")
 @ResponseBody
 public int del(@PathVariable String id){
     return rolesService.del(id);
 }
 @ApiOperation(value = "穿梭框")
@GetMapping(value = "/findTable")
public List<Roles> findAll(){
return rolesService.findTable();
}
@ApiOperation(value = "查询用户已有角色")
@GetMapping(value = "/findRoles/{userid}")
public List<Roles> findRoles(@PathVariable String userid){
 return rolesService.findRoles(userid);
}
}